package com.api.weavernorth.supplier;

import com.api.weavernorth.attend.AttendLeave;
import com.weavernorth.util.Logger4jUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.net.URLDecoder;

/**
 * @Author: bruseewang
 * @Package: com.api.weavernorth.supplier
 * @date: 2021/9/24 11:39
 * @description: 供应商新增变更流程校验接口
 */
@Path("/weavernorth/supplier")
public class supplierService extends HttpServlet {
    private Logger log = Logger4jUtil.getLoggerByName("/api/supplier/");

    /***
     * 判断供应商名称是否重复
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/checkSupplier")
    @Produces(MediaType.TEXT_PLAIN)
    public String checkDate(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        log.info("根据供应商名称查询建模表中是否已存在数据=====>");
        String strResult="1";
        try {
            //选择的日期
            String gysmc = Util.null2String(URLDecoder.decode(request.getParameter("gysmc"), "UTF-8"));
            RecordSet rs = new RecordSet();
            String strQuery = "select *  from uf_gystzsj where gysmc='" + gysmc.trim() + "'";
            log.info("查询语句：" + strQuery);
            rs.execute(strQuery);
            log.info("查询结果行数：" + rs.getCounts());
            log.info("end=====>");
            if (rs.getCounts() > 0) {
                strResult= "0";
            }
        }catch (Exception ex){
            log.info("程序异常,异常信息："+ex.toString());
            strResult="0";
        }finally {
            return strResult;
        }

    }
}
